package com.pk.platform.business.common.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.pk.platform.business.common.dao.IKindergartenDao;
import com.pk.platform.business.common.vo.KinderVO;
import com.pk.platform.business.core.dao.impl.GenericDaoImpl;
import com.pk.platform.domain.common.Kindergarten;
import com.pk.platform.domain.privilege.User;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.WebUtil;
import com.pk.platform.util.constant.Constant;
import com.pk.platform.util.filter.SystemContext;
import com.pk.platform.util.page.ListPage;
import com.pk.platform.util.page.Pager;

public class KindergartenDaoImpl extends GenericDaoImpl implements
		IKindergartenDao {

	public ListPage queryKindergarten(KinderVO kvo, Pager pager) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from kindergarten kg where 1 = 1");
		List<Object> param = new ArrayList<Object>();
		if(StringConverter.isNotNull(kvo.getKg().getKgName()))
		{
			sql.append(" and kg.kgName like ?");
			param.add("%" + kvo.getKg().getKgName() + "%");
		}
		if(StringConverter.isNotNull(kvo.getKg().getAddress()))
		{
			sql.append(" and kg.address like ?");
			param.add("%" + kvo.getKg().getAddress() + "%");
		}
		if(StringConverter.isNotNull(kvo.getKg().getTelephone()))
		{
			sql.append(" and kg.telephone like ?");
			param.add("%" + kvo.getKg().getTelephone() + "%");
		}
		sql.append(" and kg.isDel = 0");
		return this.getListPage(sql.toString(), param.toArray(), pager);
	}
	
	public List<Kindergarten> queryAllKgList()
	{
		User user = User.getWebUser();
		String privilege = user.getKgDataPrivilege();
		StringBuffer privilegeHql = new StringBuffer();
		if(StringConverter.isNotNull(privilege) && !Constant.ALL.equals(privilege))
		{
			privilegeHql.append(" and k.id in ( ").append(privilege).append(" )");
		}
		StringBuffer hql = new StringBuffer();
		hql.append("from Kindergarten k where 1 = 1 and k.isDel = 0").append(privilegeHql.toString());
		return this.getHibernateTemplate().find(hql.toString());
	}

}
